package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: syyyy
 * Date: 2025-07-08
 * Time: 18:58
 */
public class EnhanceBook implements IOperation {
    public void work(BookList bookList){
        int i=0;
        int currentSize= bookList.getUsedSize();

        if(currentSize==bookList.getBooks().length){
            System.out.println("书架已经满啦！");
        }

        System.out.println("*****增书界面*****");
        System.out.println("请输入你要添加的书的信息：");
        Scanner scanner =new Scanner(System.in);
        System.out.println("书名：");
        String name=scanner.nextLine();
        System.out.println("作者：");
        String author=scanner.nextLine();
        System.out.println("类型：");
        String type=scanner.nextLine();
        System.out.println("价格：");
        int price=scanner.nextInt();
        for (i = 0; i < currentSize; i++) {
            Book book=bookList.getBooks(i);
            if(name.equals(book.getName())&&author.equals(book.getAuthor())){
                System.out.println("这本书已经存在！");
            }
        }
        Book book =new Book(name,author,price,type);
        bookList.setBooks(book,currentSize++);
        bookList.setUsedSize(currentSize++);
        System.out.println("添加成功！");



    }
}
